<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue demo05(小结)</title>
    <script src="../build/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="newTodo" v-on:keyup.enter="addTodo">
    <ul>
        <li v-for="todo in todos">
            <span>{{todo.text}}</span>
            <button v-on:click="removeTodo($index)">Remove</button>
        </li>
    </ul>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            newTodo: '',
            todos: [
                {
                    text: 'Hello xiaobao'
                }
            ]
        },
        methods: {
            addTodo: function () {
                var text = this.newTodo.trim();

                if (text) {
                    this.todos.push({
                        text: text
                    });
                    this.newTodo = '';
                }
            },
            removeTodo: function (index) {
                this.todos.splice(index, 1);
            }
        }
    });
</script>
</body>
</html>